home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7874 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  67 lines

  1. Path: ts25-7.wla.ts.ucla.edu!wbayever
  2. From: wbayever@ucla.edu (Wayne Bayever)
  3. Newsgroups: comp.lang.c++
  4. Subject: Calling virtual functions
  5. Date: Sun, 18 Feb 1996 15:24:43
  6. Organization: UCLA
  7. Message-ID: <wbayever.1.000F69F7@ucla.edu>
  8. NNTP-Posting-Host: ts25-7.wla.ts.ucla.edu
  9. Keywords: pure virtual functions
  10. X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
  11.  
  12. I have the following two class templates:
  13.  
  14. /***************************************************************************
  15.  *  Class:  RootFinder                                                     *
  16.  *  Purpose:  Superclass for all rootfinding methods                       *
  17.  ***************************************************************************/
  18.  
  19. template <class T>
  20. class RootFinder {
  21.      .
  22.      .
  23.      .
  24.     public:
  25.         virtual BOOL FindAllRoots();   //  Calls FindRoot(complex &) several times
  26.         virtual BOOL FindRoot(complex &root) = 0;
  27. };
  28.  
  29. /***************************************************************************
  30.  *  Class:  MullerRootFinder                                               *
  31.  *  Purpose:  Implementation of Muller's root finding method               *
  32.  ***************************************************************************/
  33.  
  34. template <class T>
  35. class MullerRootFinder : public virtual RootFinder<T> {
  36.     public:
  37.         BOOL FindRoot(complex &root);
  38. };
  39.  
  40. The function   FindAllRoots() in RootFinder calls FindRoot(complex &) several 
  41. times.
  42. I am using Borland C++ 3.1 to compile my program, and no errors show up.  But 
  43. when I run the program I get an error:
  44. Pure virtual function called
  45.  
  46. My main() looks like this:
  47. void main() {
  48.      .
  49.      .
  50.      .
  51.     MullerRootFinder<double> mrf(14);
  52.      .
  53.      .
  54.      .
  55.     mrf.FindAllRoots();   <<<<<<<<  This is the line which produces the error
  56.  
  57. }
  58.  
  59. Can you not call a pure virtual function from a base class function if you 
  60. only define it in a subclass?
  61. I am going to derive several other root finding classes from RootFinder, I 
  62. hope that I can do it without copying FindAllRoots() in each class.
  63.  
  64. Please let me know if I am doing something wrong,
  65.  
  66. Wayne Bayever
  67.